package cn.innosmart.aq.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;

import java.util.HashMap;
import java.util.List;

import cn.innosmart.aq.R;

public class FishAdapter extends BaseAdapter {

    private List<HashMap<String, FishGridViewItem>> list;
    private FishGridViewItem tempGridViewItem;
    private LayoutInflater layoutInflater;

    private int width, height;

    public FishAdapter(Context context,
                       List<HashMap<String, FishGridViewItem>> list, int width, int height) {

        this.list = list;
        this.width = width;
        this.height = height;
        layoutInflater = LayoutInflater.from(context);

    }

    /**
     * 数据总数
     */
    @Override
    public int getCount() {

        return list.size();
    }

    /**
     * 获取当前数据
     */
    @Override
    public Object getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = null;

        if (layoutInflater != null) {

            view = layoutInflater
                    .inflate(R.layout.fish_item, null);


            SmartImageView imageView = (SmartImageView) view
                    .findViewById(R.id.imageView1);

            TextView tv_title = (TextView) view.findViewById(R.id.title);
            //获取自定义的类实例
            tempGridViewItem = list.get(position).get("item");
            imageView.setImageUrl(tempGridViewItem.thumbnail);

            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//            imageView.setMinimumWidth(this.width);
//            imageView.setMinimumHeight(this.width * 1080 / 850);

            ViewGroup.LayoutParams lp = imageView.getLayoutParams();
            lp.width = this.width;
            lp.height = (int) (this.width * 850 / 1080.0);
            imageView.setLayoutParams(lp);

            tv_title.setText(tempGridViewItem.name);

            TextView tv_price = (TextView) view.findViewById(R.id.tv_pricexxxxxx);
            tv_price.setText("¥" + tempGridViewItem.price);

        }
        return view;
    }


}